package cn.gd.controller.systemAdministration.organizationalStructureManagement;

import cn.gd.pojo.Department;
import cn.gd.pojo.Organizationstructure;
import cn.gd.service.systemAdministration.organizations.OrganizationsService;
import cn.gd.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin //设置允许跨域访问
@RestController
@RequestMapping("/organizationstructure")
public class OrganizationStructureController {
    @Autowired
    private OrganizationsService service;

    /**
     * 获取部门和组织结构名称
     * @return
     */
    @GetMapping("/getOrgNameAndDeptName")
    public Result<List<Organizationstructure>> getOrgNameAndDeptName() {
        return Result.ok(service.getAllOrganizations());
    }

    /**
     * 获取部门根据ID
     * @param deptId
     * @return
     */
    @GetMapping("/getDepartmentById")
    public Result<Department> getDepartmentById(Integer deptId) {
        return Result.ok(service.getDepartmentById(deptId));
    }

    /**
     * 获取组织结构名称根据ID
     * @param deptId
     * @return
     */
    @GetMapping("/getOrganizationalStructureNameByDeptID")
    public Result<Organizationstructure> getOrganizationalStructureNameByDeptID(Integer deptId,Integer orgId) {
        return Result.ok(service.getOrganizationStructureNameById(deptId,orgId));
    }
//
    /**
     * 修改部门根据ID
     * @param department
     * @return
     */
    @PutMapping("/updateDepartmentById")
    public Result<Boolean> updateDepartmentById(@RequestBody Department department){
        return Result.ok(service.updateDepartmentById(department));
    }

    /**
     * 删除部门根据ID
     * @param deptId
     * @return
     */
    @DeleteMapping("/deleteDepartmentById")
    public Result<Boolean> deleteDepartmentById(Integer deptId){
        return Result.ok(service.deleteDepartmentById(deptId));
    }

    /**
     * 获取组织结构信息根据ID
     */
    @GetMapping("/getOrganizationalByOrgId")
    public Result<Organizationstructure> getOrganizationalByOrgId(Integer orgId){
        return Result.ok(service.getOrganizationstructureByOrgId(orgId));
    }

    /**
     * 修改组织结构信息根据ID
     * @param organization
     * @return
     */
    @PutMapping("/updateOrganizationalByOrgId")
    public Result<Boolean> updateOrganizationalByOrgId(@RequestBody Organizationstructure organization){
        return Result.ok(service.updateOrganizationalByOrgId(organization));
    }

    /**
     * 新增部门信息
     * @param department
     * @param orgId
     * @return
     */
    @PostMapping("addDepartment")
    public Result<Boolean> addDepartment(@RequestBody Department department,Integer orgId){
        return Result.ok(service.addDepartment(department,orgId));
    }

    /**
     * 删除组织结构根据组织ID
     * @param orgId
     * @return
     */
    @DeleteMapping("/deleteOrganizational")
    public Result<Boolean> deleteOrganizational(Integer orgId){
        return Result.ok(service.deleteOrganizationStructureByOrgId(orgId));
    }

    /**
     * 新增组织结构信息
     * @param organizationstructure
     * @return
     */
    @PostMapping("/addorganizational")
    public Result<Boolean> addorganizational(@RequestBody Organizationstructure organizationstructure){
        return Result.ok(service.addOrganizationStructure(organizationstructure));
    }
}
